import http from '../../../common/httpUtil';
import * as types from './operatorMutationTypes';

const actions = {
  queryOperator({commit}, {pageIndex = 1, pageSize = 10} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.getRaw(`admin/organ/getAgents?pageIndex=${pageIndex}&pageSize=${pageSize}&profileName=${''}`)
      .then(data => {
        console.log(data)
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {files: data.data.result});
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_SUC, {totalCount: data.data.totalCount})
      });
  },
  searchOperator({commit}, {profileName, pageIndex = 1, pageSize = 10} = {}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);
    return http.get(`admin/organ/getAgents?pageIndex=${pageIndex}&pageSize=${pageSize}&profileName=${profileName}`)
      .then(data => {
        console.log(data)
        var files = data
        commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {files});
      });
  },
  searchOperatorCount({commit}, {profileName, pageIndex = 1, pageSize = 10}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_BEGIN);
    return http.getRaw(`admin/organ/getAgents?profileName=${profileName}&pageIndex=${pageIndex}&pageSize=${pageSize}`).then(data => {
      var totalCount = data.body.totalCount
      console.log(data)
      commit(types.SYS_FILE_UPLOAD_QUERY_FILES_COUNT_SUC, {totalCount})
    });
  },
  editOperator({commit}, {formData}) {
    return http.post(`admin/organ/update/agent?agentId=${formData.agentId}&name=${formData.organAgentName}&mobile=${formData.organAgentMobile}&idCard=${formData.organAgentIdcard}`).then(data => {
      console.log(data)
      commit(types.SYS_FILE_UPLOAD_UPDATE_SUC, {formData})
      return data
    });
  }
};


export default actions;
